package com.mmp.common.util;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class DateUtil {

	private final static String DATE_FORMAT = "dd/MM/yyyy";

	public DateUtil() {
		super();
	}

	public static Date convertToDate(String dateStr) {
		try {
			return new SimpleDateFormat(DATE_FORMAT, Locale.ENGLISH).parse(dateStr);
		} catch (ParseException e) {
			// Common.log("com.mmp.common.util.DateUtil :: convertToDate(String dateStr) :: malformed input date string");
			return null;
		}

	}

	public static Timestamp getCurrentTimeStamp() {
		return new Timestamp(new Date().getTime());
	}

	public static Date getCurrentDate() {
		return new Date();
	}

	public static String getDateString(Date d) {
		return getDateString(d, "dd/MM/yyyy");
	}

	public static String getDateString(Date d, String format) {
		if (d != null)
			return new SimpleDateFormat(format).format(d);
		return "";
	}

	public static void main(String[] args) {
		Common.log(getDateString(new Date()));
	}
}
